<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Cache;

class Transmeaning extends BaseModel
{
//    use SoftDeletes;

    public $timestamps = false;
    public $table = 'transmeaning';
    static $unguarded = false;

    static function trans($keyword = null)
    {
        if (empty($keyword)) return $keyword;

        $res = Cache::get("cache_transmeaning_list");
        if (empty($res)) {
            $res = Transmeaning::where("id", ">", 0)->get(['before', 'after'])->toArray();
            Cache::set("cache_transmeaning_list", $res);
        }

        foreach ($res as $k => $v) {
            $keyword = str_replace($v['before'], $v['after'], $keyword);
        }

        return $keyword;
    }

}